package com.bytz.modules.cms.domain.impl.order;

import com.bytz.modules.cms.domain.MallOrderProcessor;
import com.bytz.modules.cms.domain.model.order.MallOrderProcessContext;
import com.bytz.modules.cms.order.model.OrderItemModel;

import java.util.Objects;

/**
 * 订单提交时填充信息处理器
 */
public class MallOrderDeliveryDateProcessor extends MallOrderAbstractProcessor implements MallOrderProcessor {

    public MallOrderDeliveryDateProcessor(int sequence) {
        super(sequence);
    }

    @Override
    public void doProcess(MallOrderProcessContext context) {

        if (context.getSubmit()) {
            Integer maxDeliveryDate = context.getOrder().getOrderItemList().stream()
                    .map(OrderItemModel::getDeliveryDate)
                    .filter(Objects::nonNull)
                    .max(Integer::compare)
                    .orElse(null);
            context.getOrder().setDeliveryDate(maxDeliveryDate);
        }
    }
}